#ifndef VS_SERIAL_H_
#define VS_SERIAL_H_

#include "WinMutex.h"

class cVS_Serial
{
public:
	cVS_Serial();
	~cVS_Serial();

	bool open(CString strComport = _T("\\\\.\\COM1"), DWORD baudrate = CBR_19200);
	void close();

	DWORD write(LPCVOID pData, DWORD len);
	DWORD read(LPVOID pDest, DWORD len, DWORD wait_time = 1000);

	void clearbuffer();

private:
	bool IsNT();

	DWORD write_data(LPCVOID pData, DWORD len);
	DWORD read_data(LPVOID pDest, DWORD len, DWORD wait_time);

private:
	HANDLE m_ComHandle;
	cWinMutex m_ReadMutex;
	cWinMutex m_WriteMutex;

	OVERLAPPED m_ROver;
	OVERLAPPED m_WOver;

	bool bIsOpen;	
};

#endif
